﻿Public Class frmEmployerManagement
    Dim dbBase As New dbEmployer
    Dim dbSys As New dbSystem
    Dim frmCtrl As New control
    Dim dsBase As DataSet
    Dim TypeAct As String

    Private Sub frmEmployerManagement_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        frmCtrl.reDesign(Me)
        TypeAct = ""
        UcGridFilter1.Enabled = True
        Textbox(False, False)
        dsBase = dbBase.GetEmployerList()
        Dim dsPosition As DataSet = dbSys.GetJobPositionList()
        cmbPosition.DataSource = dbSys.GetJobPositionList().Tables(0)
        cmbPosition.ValueMember = "posGenID"
        cmbPosition.DisplayMember = "posName"
        UcHeader1.Iniliaze("Management : Employer", Me, Nothing, UcGridFilter1.getDataGridView(), "EmployerID", True)
        UcGridFilter1.Initialize(dsBase.Tables(0), "EmployerID", UcHeader1, Me, True)
        If (dsBase IsNot Nothing) Then
            UcGridFilter1.getDataGridView().Columns("EmployerID").Visible = False
            UcGridFilter1.getDataGridView().Columns("Employer Address").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
            UcGridFilter1.getDataGridView().Columns("posGenID").Visible = False
        End If
    End Sub

    Private Sub Textbox(st As Boolean, clear As Boolean)
        cmbPosition.Enabled = st
        btnChangePicture.Enabled = st
        If (st) Then
            st = False
        Else : st = True
        End If
        txtName.ReadOnly = st
        txtName.BackColor = Color.White
        txtAddress.ReadOnly = st
        txtAddress.BackColor = Color.White
        txtPhone.ReadOnly = st
        txtPhone.BackColor = Color.White
        UcGridFilter1.Enabled = st
        If (clear) Then
            txtGenID.Text = ""
            txtName.Text = ""
            txtAddress.Text = ""
            txtPhone.Text = ""
        End If
    End Sub

    Private Sub tsNew_Click(ByVal sender As Object) Handles UcHeader1.tsNewClick
        TypeAct = "I"
        Textbox(True, True)
    End Sub

    Private Sub tsEdit_Click(ByVal sender As Object) Handles UcHeader1.tsEditClick
        TypeAct = "U"
        Textbox(True, False)
    End Sub

    Private Sub tsDelete_Click(ByVal sender As Object) Handles UcHeader1.tsDeleteClick
        If (txtGenID.Text.Trim() <> "") Then
            TypeAct = "D"
            Dim result As Boolean = dbBase.EmployerManagement(TypeAct, txtGenID.Text.Trim(), txtName.Text.Trim(), txtAddress.Text.Trim(), txtPhone.Text.Trim(), cmbPosition.SelectedValue, frmGlobal.LoginID)
            If (result) Then
                frmCtrl.openChild(New frmEmployerManagement, Me.ParentForm)
            Else : MessageBox.Show("Error in Delete Progress")
            End If
        Else : MessageBox.Show("Please Choose User First")
        End If
    End Sub

    Private Sub tsPrint_Click(ByVal sender As ucHeader) Handles UcHeader1.tsPrintClick
        ''Event 
        MessageBox.Show("Not included in prototype")
    End Sub

    Private Sub tsSave_Click(ByVal sender As Object) Handles UcHeader1.tsSaveClick
        Dim status As Boolean = True
        If (txtName.Text.Trim() <> "" And txtAddress.Text.Trim() <> "" And txtPhone.Text.Trim() <> "" And status = True) Then
            Dim result As Boolean = dbBase.EmployerManagement(TypeAct, txtGenID.Text.Trim(), txtName.Text.Trim(), txtAddress.Text.Trim(), txtPhone.Text.Trim(), cmbPosition.SelectedValue, frmGlobal.LoginID)
            If (result) Then
                frmCtrl.openChild(New frmEmployerManagement, Me.ParentForm)
            Else : MessageBox.Show("Error in Save Progress")
            End If
        Else : MessageBox.Show("Please Fill All Field")
        End If
    End Sub

    Private Sub tsRefresh_Click(ByVal sender As Object) Handles UcHeader1.tsRefreshClick
        frmCtrl.openChild(New frmEmployerManagement, Me.ParentForm)
    End Sub

    Private Sub tsCancel_Click(ByVal sender As Object) Handles UcHeader1.tsCancelClick
        frmCtrl.openChild(New frmEmployerManagement, Me.ParentForm)
    End Sub

    Private Sub GridCellEnter_Click(ByVal sender As ucGridFilter, KeyValue As String) Handles UcGridFilter1.GridCellEnter
        Dim dvFind As DataView = New DataView(dsBase.Tables(0))
        dvFind.RowFilter = "[EmployerID] = '" & KeyValue & "'"
        txtGenID.Text = dvFind.Item(0).Row("EmployerID").ToString()
        txtName.Text = dvFind.Item(0).Row("Employer FullName").ToString()
        txtAddress.Text = dvFind.Item(0).Row("Employer Address").ToString()
        txtPhone.Text = dvFind.Item(0).Row("Employer Phone").ToString()
        cmbPosition.SelectedValue = dvFind.Item(0).Row("posGenID").ToString()
    End Sub

    Private Sub btnChangePicture_Click(sender As Object, e As EventArgs) Handles btnChangePicture.Click
        MessageBox.Show("Not included in prototype")
    End Sub
End Class